<html>
<head>
<link href="http://www.google.com/uds/css/gsearch.css" type="text/css"
          rel="stylesheet"/>
<script src="http://maps.google.com/maps?file=api&amp;v=2.x" type="text/javascript">
</script>
<script src="http://www.google.com/uds/api?file=uds.js&v=1.0"
    type="text/javascript">
	</script>
<script src="http://www.google.com/uds/solutions/mapsearch/gsmapsearch.js"
    type="text/javascript">
	</script>
	
	<!-- ajax search stylesheet, map search stylesheet -->
<link href="http://www.google.com/uds/css/gsearch.css" rel="stylesheet"
    type="text/css"/>
<link href="http://www.google.com/uds/solutions/mapsearch/gsmapsearch.css"
    rel="stylesheet" type="text/css"/>

<script type="text/javascript">
var map;
var lastMarker;
var cocoaApplication;

var searchResultIcon = new GIcon(); 
searchResultIcon.image = "Pin.png"; 
searchResultIcon.shadow = "PinShadow.png"; 
searchResultIcon.iconSize = new GSize(32, 32); 
searchResultIcon.shadowSize = new GSize(32, 32); 
searchResultIcon.iconAnchor = new GPoint(15,32); 
searchResultIcon.infoWindowAnchor = new GPoint(25,16); 
searchResultIcon.infoShadowAnchor = new GPoint(25,16); 

var droppedPinIcon = new GIcon(); 
droppedPinIcon.image = "Pin_user.png"; 
droppedPinIcon.shadow = "PinShadow.png"; 
droppedPinIcon.iconSize = new GSize(32, 32); 
droppedPinIcon.shadowSize = new GSize(32, 32); 
droppedPinIcon.iconAnchor = new GPoint(15,32); 
droppedPinIcon.infoWindowAnchor = new GPoint(25,16); 
droppedPinIcon.infoShadowAnchor = new GPoint(25,16); 

function searchMe(searchTerm) { 

	var localSearch = new GlocalSearch();
	localSearch.setCenterPoint(map);
	localSearch.setSearchCompleteCallback(null, function(){
	var result = localSearch.results[0];
	var point = new GLatLng(result.lat, result.lng);
				
	if (lastMarker != null)
	{
		map.removeOverlay(lastMarker);
	}
		lastMarker = new GMarker(point, searchResultIcon);
		map.addOverlay(lastMarker);
		map.setCenter(point, 15);
		cocoaApplication.refreshZoomSlider_(map.getZoom());

		lastMarker.openInfoWindowHtml("<h1>"+result.title+"</h1>");		
	});
	
	localSearch.execute(searchTerm);

} 

function zoomIn() {

var currentZoom = map.getZoom();
map.setZoom(currentZoom+1);

cocoaApplication.refreshZoomSlider_(map.getZoom());

//cocoaApplication.log_(currentZoom);
}

function zoomOut() {
	var currentZoom = map.getZoom();
	map.setZoom(currentZoom-1);
	cocoaApplication.refreshZoomSlider_(map.getZoom());
}

function loadPin(lat, lng, title)
{
	var location = new GLatLng(lat, lng)
	var marker = new GMarker(location, {draggable: true, icon: droppedPinIcon} );
	map.addOverlay(marker);

	marker.openInfoWindowHtml("<h1>"+title+"</h1>");

	GEvent.addListener(marker, "dragstart", function() {
		map.closeInfoWindow();
		});

	GEvent.addListener(marker, "dragend", function() {
				marker.openInfoWindowHtml("<h1>"+title+"</h1>");
				
		});
		
	GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml("<h1>"+title+"</h1>");
				map.panTo(marker.getLatLng());
				map.setCenter(marker.getLatLng(), 15);
				cocoaApplication.refreshZoomSlider_(map.getZoom());

		});
}


function dropPin(passedTitle) {
	var bounds = map.getBounds();
	var center = bounds.getCenter();
	var marker = new GMarker(center, {draggable: true, icon: droppedPinIcon});
	map.addOverlay(marker);

	marker.openInfoWindowHtml("<h1>"+passedTitle+"</h1>");

	GEvent.addListener(marker, "dragstart", function() {
		map.closeInfoWindow();
		});

	GEvent.addListener(marker, "dragend", function() {
				marker.openInfoWindowHtml("<h1>"+passedTitle+"</h1>");
					var pointArray = new Array();
					pointArray[0]=marker.getLatLng().lat();
					pointArray[1]=marker.getLatLng().lng();
					pointArray[2]=passedTitle;
	
					cocoaApplication.retreiveNewPinLocation_(pointArray);
		});
		
	GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml("<h1>"+passedTitle+"</h1>");
				map.panTo(marker.getLatLng());
			});
		
	var pointArray = new Array();
	pointArray[0]=marker.getLatLng().lat();
	pointArray[1]=marker.getLatLng().lng();
	pointArray[2]=passedTitle;
	
	cocoaApplication.retreiveNewPinLocation_(pointArray);

}

function setZoom(value)
{
	map.setZoom(value);
}


function useStandardMap()
{
        map.setMapType(G_NORMAL_MAP);
}

function useSatelliteMap()
{
        map.setMapType(G_SATELLITE_MAP);
}

function useHybridMap()
{
        map.setMapType(G_HYBRID_MAP);
}


function onLoad() { 
map = new GMap2(document.getElementById('map'));
map.setCenter(new GLatLng(37.26, -112.949), 5);

map.enableContinuousZoom();
map.enableScrollWheelZoom();
map.enableDoubleClickZoom();
map.enableDragging();          
 
}

</script>
</head>
 <body onload='onLoad()' style='font-family: Arial, sans serif'>
<div id='map' style='width:100%; height: 100%;'></div>

</body>
</html>
